package com.yanqu.road.server.cmd.activity.chuhan.cross;

import com.yanqu.road.entity.enums.eLogMoneyType;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.ChuHanProto;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.command.Command;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.player.CurrencyModule;
import com.yanqu.road.server.manger.player.GamePlayerMgr;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameProtocol;
import com.yanqu.road.server.protocol.Protocol;
import io.netty.channel.ChannelHandlerContext;


@Cmd(code = GameProtocol.S_CROSS_CHUHAN_GET_POS_REWARD, desc = "")
public class ChuHanCrossGetPosRewardCmd implements Command {

    @Override
    public void execute(ChannelHandlerContext ctx, YanQuMessage packet) throws Exception {
        ChuHanProto.ChuHanPosGetRewardRespMsg reqMsg = ChuHanProto.ChuHanPosGetRewardRespMsg.parseFrom(packet.getBytes());
        long userId = packet.getPlayerId();
        GamePlayer player = GamePlayerMgr.getOnlinePlayer(userId);
        if(player != null){
            ChuHanProto.ChuHanPosGetRewardRespMsg.Builder respMsg = ChuHanProto.ChuHanPosGetRewardRespMsg.newBuilder();
            player.getModule(CurrencyModule.class).addCurrency(reqMsg.getReward(), eLogMoneyType.ChuHan,eLogMoneyType.ChuHanGetPosReward);
            respMsg.setRet(reqMsg.getRet());
            respMsg.setReward(reqMsg.getReward());
            player.sendPacket(Protocol.S_CHUHAN_GET_POS_REWARD % 20000, respMsg);
        }
    }

}
